<?php
//评价
namespace app\adminbackstage\model;

use think\Model;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class Evaluation extends Model{
    protected $type = [
        'img_json' => 'json',
    ];
    // 模型初始化
    protected static function init()
    {
        parent::init();
        //TODO:初始化内容
    }
    
    //评价列表
    public static function evaluationList($where,$page,$num){
        $list = self::alias('e')
        ->field('e.*,u.username,u.phone,o.o_pro_num,p.p_name,p.p_num')
        ->leftjoin('user u','u.uid = e.uid')
        ->leftjoin('order o','o.id = e.oid')
        ->leftjoin('product p','p.id = e.pid')
        ->where($where)
        ->limit(($page-1)*$num,$num)
        ->select();
        return $list;
    }
    
    //评价列表
    public static function evaluationSelect($where){
        $list = self::where($where)
        ->select();
        return $list;
    }
    
    //评价详情
    public static  function evaluationInfo($where){
        $info = self::alias('e')
        ->field('e.*,u.username,u.phone,o.o_pro_num,p.p_name,p.img,p.p_num')
        ->leftjoin('user u','u.uid = e.uid')
        ->leftjoin('order o','o.id = e.oid')
        ->leftjoin('product p','p.id = e.pid')
        ->where($where)
        ->find();
        return $info;
    }
    
    //评价数
    public static function evaluationCount($where) {
        return self::alias('e')
        ->field('e.*,u.username,u.phone')
        ->leftjoin('user u','u.uid = e.uid')
        ->leftjoin('order o','o.id = e.oid')
        ->leftjoin('product p','p.id = e.pid')
        ->where($where)
        ->count();
    }

    //评价修改
    public static function evaluationEdit($id,$update){
        $in = self::update($update, ['id' => $id]);
        return $in;
    }
    

    //评价添加
    public static function evaluationAdd(array $data){
        return self::create($data);
    }
  
}
